package com.shuhe.handler;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.shuhe.JettyServer;
import com.shuhe.common.MyDateUtils;
import com.shuhe.domain.mxgc.CommonResponseBody;
import com.shuhe.domain.mxgc.ExeclOperate;
import com.shuhe.domain.mxgc.SqlRequestBody;
import com.shuhe.domain.token.Token;
import com.shuhe.metastore.DBSql;
import com.shuhe.metastore.MetaMysql;
import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.servlet.ServletFileUpload;
import org.apache.log4j.Logger;
import org.apache.poi.hssf.usermodel.HSSFPatriarch;
import org.apache.poi.hssf.usermodel.HSSFPicture;
import org.apache.poi.hssf.usermodel.HSSFPictureData;
import org.apache.poi.hssf.usermodel.HSSFShape;
import org.apache.poi.ss.usermodel.*;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.sql.Connection;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import static com.shuhe.common.Base64.byteConvertBase64;
import static com.shuhe.common.Base64.fileConvertBase64;
import static com.shuhe.common.CommonFunction.*;
import static com.shuhe.common.MyDateUtils.getDataString;
import static com.shuhe.domain.mxgc.ExeclOperate.importEXECL;
import static com.shuhe.handler.CommonHandler.reqExpire;
import static com.shuhe.handler.ServiceDetail.*;


public class ServiceHandler extends HttpServlet {

    private static Logger logger = Logger.getLogger(ServiceHandler.class);


    @Override
    protected void doOptions(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp = setResponse(resp);
    }


    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        try {
            resp = setResponse(resp);

            String id = req.getParameter("id");
            if (id == null || id.isEmpty()) {
                resp.setStatus(HttpServletResponse.SC_BAD_REQUEST);
                resp.getWriter().write("缺少文件ID参数");
                return;
            }
            String operateType = req.getParameter("operateType");
            if (operateType == null || operateType.isEmpty()) {
                resp.setStatus(HttpServletResponse.SC_BAD_REQUEST);
                resp.getWriter().write("缺少operateType参数");
                return;
            }
            if (operateType.equals("getSource")) {
                Connection metaConn = null;
                try {
                    metaConn = MetaMysql.connect();
                    String sql = "SELECT file_name FROM mxgc_assessment_source WHERE id = '" + id + "'";
                    ResultSet rs = MetaMysql.querySql(metaConn, sql);
                    if (rs.next()) {
                        String fileName = rs.getString("file_name");
                        String filePath = System.getProperty("user.dir");
                        filePath = filePath + File.separator + fileName;
                        File storeFile = new File(filePath);

                        // 检查文件是否存在
                        if (storeFile.exists() && storeFile.isFile()) {
                            // 设置响应头
                            resp.setContentType("application/octet-stream");
                            resp.setContentLength((int) storeFile.length());
                            resp.setHeader("Content-Disposition", "attachment; filename=\"" + fileName + "\"");

                            // 读取文件并输出到响应流
                            FileInputStream fis = new FileInputStream(storeFile);
                            byte[] buffer = new byte[4096];
                            int bytesRead;
                            while ((bytesRead = fis.read(buffer)) != -1) {
                                resp.getOutputStream().write(buffer, 0, bytesRead);
                            }
                            fis.close();
                            resp.getOutputStream().flush();
                        } else {
                            resp.setStatus(HttpServletResponse.SC_NOT_FOUND);
                            resp.getWriter().write("文件不存在");
                        }
                    } else {
                        resp.setStatus(HttpServletResponse.SC_NOT_FOUND);
                        resp.getWriter().write("未找到对应的文件记录");
                    }
                } finally {
                    closeDb(metaConn);
                }
            }
        } catch (Exception ex) {
            ex.printStackTrace();
            logger.error("文件下载失败: " + ex.getMessage());
            resp.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
            resp.getWriter().write("文件下载失败: " + ex.getMessage());
        }
    }


    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        try {
//            if (!ClientInterceptor.preHandle(req, resp)) {
//                throw new Exception("非法客户端访问");
//            }

            resp = setResponse(resp);

            //文件上传
            if (ServletFileUpload.isMultipartContent(req)) {
                DiskFileItemFactory factory = new DiskFileItemFactory();
                ServletFileUpload upload = new ServletFileUpload(factory);
                upload.setHeaderEncoding("UTF-8");
                Connection metaConn = null;
                try {
                    metaConn = MetaMysql.connect();
                    // 解析请求的内容提取文件数据
                    List<FileItem> formItems = upload.parseRequest(req);

                    if (formItems != null && formItems.size() > 0) {
                        String filePath = System.getProperty("user.dir");
                        String fileName = "";
                        // 迭代表单数据
                        for (FileItem item : formItems) {
                            // 处理不在表单中的字段
                            if (!item.isFormField()) {
                                String name = new File(item.getName()).getName();
                                String userName = req.getParameter("userName");
                                if (userName == null) {
                                    userName = "";
                                }
                                fileName = userName + '_' + name;
                                filePath = filePath + File.separator + fileName;
                                logger.info("filePath:" + filePath);
                                File storeFile = new File(filePath);
                                item.write(storeFile);

                                String operateType = req.getParameter("operateType");
                                if (operateType.equals("addImage")) {
                                    //大屏设计 上传图片用
                                    String content = fileConvertBase64(storeFile.getPath());
                                    storeFile.delete();
                                    String id = getUUID();
                                    String sql = "insert into chart_screen_images(id, name, content, user_name) " +
                                            "values('" + id + "', '" + name + "', '" + content + "', '" + userName +
                                            "')";
                                    MetaMysql.execSql(metaConn, sql);
                                }
                            }
                        }
                        String operateType = req.getParameter("operateType");
                        if (operateType.equals("addSource")) {
                            String source_name = "";
                            String source_type = "";
                            String source_description = "";
                            for (FileItem item : formItems) {
                                if (item.isFormField()) {
                                    if (item.getFieldName().equals("source_name")) {
                                        source_name = item.getString("UTF-8");
                                    }
                                    if (item.getFieldName().equals("source_type")) {
                                        source_type = item.getString("UTF-8");
                                    }
                                    if (item.getFieldName().equals("source_description")) {
                                        source_description = item.getString("UTF-8");
                                    }
                                }
                            }
                            String id = getUUID();
                            String sql = "insert into mxgc_assessment_source(id, source_name, " +
                                    "source_type, source_description, upload_time, file_name) " +
                                    "values('" + id + "', '" + source_name + "', '" + source_type + "', '"
                                    + source_description + "', '" + MyDateUtils.getNowDate() + "', '" +
                                    fileName + "')";
                            MetaMysql.execSql(metaConn, sql);

                        }
                    }
                    resp.getWriter().write("文件上传成功!");
                    return;
                } catch (Exception ex) {
                    ex.printStackTrace();
                    resp.getWriter().write("文件上传失败!");
                    return;
                } finally {
                    closeDb(metaConn);
                }
            }


            String tokenKey = req.getHeader("token");
            Token token = JettyServer.getGlobalToken(tokenKey);
            String bodyStr = readAsChars(req);
            JSONObject bodyJson = JSONObject.parseObject(bodyStr);
            SqlRequestBody sqlReq = JSONObject.toJavaObject(bodyJson, SqlRequestBody.class);

            //操作日志
            reqExpire(req, bodyJson);

            logger.info(sqlReq.getOperateType());

            if (sqlReq.getOperateType().equals("importEXECL")) {
                //通过模板， 导入EXECL文件用
                String sqlResp = importEXECL(bodyJson);
                resp.getWriter().write(sqlResp);
            }

            if (sqlReq.getOperateType().equals("reqScreenOperateLog")) {
                //大屏报存操作日志
                String sqlResp = reqScreenOperateLog(sqlReq);
                resp.getWriter().write(sqlResp);
                logger.info(sqlResp);
            }

            if (sqlReq.getOperateType().equals("reqUserQuit")) {
                //用户退出，目前是假的
                String sqlResp = reqScreenOperateLog(sqlReq);
                resp.getWriter().write(sqlResp);
                logger.info(sqlResp);
            }

            if (sqlReq.getOperateType().equals("reqScreenThemeQuery")) {
                //大屏主题查询
                String sqlResp = reqScreenThemeQuery(sqlReq);
                resp.getWriter().write(sqlResp);
                logger.info(sqlResp);
            }
            if (sqlReq.getOperateType().equals("reqGetColumnsByList")) {
                //根据表名得到字段列表
                String sqlResp = reqGetColumnsByList(bodyJson);
                resp.getWriter().write(sqlResp);
                logger.info(sqlResp);
            }
            if (sqlReq.getOperateType().equals("reqNeo4jConnect")) {
                //图库连接属性
                String sqlResp = reqNeo4jConnect(sqlReq);
                resp.getWriter().write(sqlResp);
                logger.info(sqlResp);
            }

            if (sqlReq.getOperateType().equals("reqNodeBaseQuery")) {
                //关系实体定义查询
                String sqlResp = reqNodeBaseQuery(sqlReq);
                resp.getWriter().write(sqlResp);
                logger.info(sqlResp);
            }
            if (sqlReq.getOperateType().equals("reqNodeRelationQuery")) {
                //关系实体关系查询
                String sqlResp = reqNodeRelationQuery(sqlReq);
                resp.getWriter().write(sqlResp);
                logger.info(sqlResp);
            }
            if (sqlReq.getOperateType().equals("reqNodeBaseSave")) {
                //关系实体定义保存
                String sqlResp = reqNodeBaseSave(bodyJson);
                resp.getWriter().write(sqlResp);
                logger.info(sqlResp);
            }
            if (sqlReq.getOperateType().equals("reqNodeBaseDelete")) {
                //关系实体定义删除
                String sqlResp = reqNodeBaseDelete(bodyJson);
                resp.getWriter().write(sqlResp);
                logger.info(sqlResp);
            }
            if (sqlReq.getOperateType().equals("reqNodeRelationSave")) {
                //关系实体关系保存
                String sqlResp = reqNodeRelationSave(bodyJson);
                resp.getWriter().write(sqlResp);
                logger.info(sqlResp);
            }
            if (sqlReq.getOperateType().equals("reqNodeRelationUpdate")) {
                //关系实体关系更新数据
                String sqlResp = reqNodeRelationUpdate(bodyJson);
                resp.getWriter().write(sqlResp);
                logger.info(sqlResp);
            }
            if (sqlReq.getOperateType().equals("reqNodeRelationIsTask")) {
                //关系设为任务jqh 2024.2.1
                String sqlResp = reqNodeRelationIsTask(bodyJson);
                resp.getWriter().write(sqlResp);
                logger.info(sqlResp);
            }
            if (sqlReq.getOperateType().equals("reqUpdatePassword")) {
                //密码修改
                String sqlResp = reqUpdatePassword(sqlReq);
                resp.getWriter().write(sqlResp);
                logger.info(sqlResp);
            }
            if (sqlReq.getOperateType().equals("roleQuery")) {
                //角色查询
                String sqlResp = reqRoleQuery(sqlReq);
                resp.getWriter().write(sqlResp);
                logger.info(sqlResp);
            }
            if (sqlReq.getOperateType().equals("roleDelete")) {
                //角色删除
                String sqlResp = reqRoleDelete(bodyJson);
                resp.getWriter().write(sqlResp);
                logger.info(sqlResp);
            }
            if (sqlReq.getOperateType().equals("roleSave")) {
                //角色保存
                String sqlResp = reqRoleSave(bodyJson);
                resp.getWriter().write(sqlResp);
                logger.info(sqlResp);
            }
            if (sqlReq.getOperateType().equals("user_delete")) {
                //用户删除
                String sqlResp = reqUserDelete(bodyJson);
                resp.getWriter().write(sqlResp);
                logger.info(sqlResp);
            }
            if (sqlReq.getOperateType().equals("user_save")) {
                //用户保存
                String sqlResp = reqUserSave(bodyJson);
                resp.getWriter().write(sqlResp);
                logger.info(sqlResp);
            }
            if (sqlReq.getOperateType().equals("reqCheckFunc")) {
                //常量函数测试
                String sqlResp = reqCheckFunc(sqlReq);
                resp.getWriter().write(sqlResp);
                logger.info(sqlResp);
            }
            if (sqlReq.getOperateType().equals("reqMakeToken")) {
                //生成登录token
                String sqlResp = reqMakeToken(sqlReq);
                resp.getWriter().write(sqlResp);
                logger.info(sqlResp);
            }
            //先进行登录日志保存，然后进行登录效验
            if (sqlReq.getOperateType().equals("reqLogin")) {
                //登录日志保存
                String sqlResp = reqLogin(sqlReq);
                resp.getWriter().write(sqlResp);
                logger.info(sqlResp);
            }
            if (sqlReq.getOperateType().equals("reqVerify")) {
                //登录效验
                String sqlResp = reqVerify(sqlReq);
                resp.getWriter().write(sqlResp);
                logger.info(sqlResp);
            }
            if (sqlReq.getOperateType().equals("loadModel")) {
                //加载旧模型  MxResponseBody
                String sqlResp = loadModel(sqlReq);
                resp.getWriter().write(sqlResp);
                //logger.info(sqlResp);
            }
            if (sqlReq.getOperateType().equals("reqGetScreenImages")) {
                //加载图片列表
                String sqlResp = reqGetScreenImages(sqlReq);
                resp.getWriter().write(sqlResp);
                //logger.info(sqlResp);
            }
            if (sqlReq.getOperateType().equals("reqSaveModel")) {
                //保存模型
                String sqlResp = reqSaveModel(sqlReq);
                resp.getWriter().write(sqlResp);
                logger.info(sqlResp);
            }
            if (sqlReq.getOperateType().equals("reqSaveComponent")) {
                //保存分析配置
                String sqlResp = reqSaveComponent(sqlReq);
                resp.getWriter().write(sqlResp);
                logger.info(sqlResp);
            }
            if (sqlReq.getOperateType().equals("reqSaveScreen")) {
                //保存看板配置
                String sqlResp = reqSaveScreen(sqlReq);
                resp.getWriter().write(sqlResp);
                logger.info(sqlResp);
            }
            if (sqlReq.getOperateType().equals("judgeTableName")) {
                //判断输出表是否重复
                String sqlResp = judgeTableName(sqlReq);
                resp.getWriter().write(sqlResp);
                logger.info(sqlResp);
            }
            if (sqlReq.getOperateType().equals("reqDeleteData")) {
                //删除自有数据
                String sqlResp = reqDeleteData(sqlReq);
                resp.getWriter().write(sqlResp);
                logger.info(sqlResp);
            }
            if (sqlReq.getOperateType().equals("reqRemoveScreenImages")) {
                //删除看板组合中的图片
                String sqlResp = reqRemoveScreenImages(sqlReq);
                resp.getWriter().write(sqlResp);
                logger.info(sqlResp);
            }
            if (sqlReq.getOperateType().equals("reqSaveFile")) {
                //EXECL文件内容保存
                //执行建表，查询
                String sqlResp = reqSaveFile(sqlReq, bodyJson);
                resp.getWriter().write(sqlResp);
                logger.info(sqlResp);
            }
            if (sqlReq.getOperateType().equals("reqGetScreenTree")) {
                //分析看板得到目录及其组件
                String sqlResp = reqGetScreenTree(sqlReq);
                resp.getWriter().write(sqlResp);
                //logger.info(sqlResp);
            }
            if (sqlReq.getOperateType().equals("reqGetShareComponentAndScreen")) {
                //得到所有共享的分析组件及看板
                String sqlResp = reqGetShareComponentAndScreen(sqlReq);
                resp.getWriter().write(sqlResp);
                //logger.info(sqlResp);
            }
            if (sqlReq.getOperateType().equals("reqGetPassTables")) {
                //查询模型定义表列表
                String sqlResp = reqGetPassTables(sqlReq);
                resp.getWriter().write(sqlResp);
                logger.info(sqlResp);
            }
            if (sqlReq.getOperateType().equals("reqGetTables")) {
                //查询模型定义表列表
                String sqlResp = reqGetTables(sqlReq);
                resp.getWriter().write(sqlResp);
                logger.info(sqlResp);
            }
            if (sqlReq.getOperateType().equals("reqGetMyTables")) {
                //查询模型定义表列表
                String sqlResp = reqGetTables(sqlReq);
                resp.getWriter().write(sqlResp);
                logger.info(sqlResp);
            }
            if (sqlReq.getOperateType().equals("reqGetColumns")) {
                //查询字段列表
                String sqlResp = reqGetColumns(sqlReq);
                resp.getWriter().write(sqlResp);
                logger.info(sqlResp);
            }
            if (sqlReq.getOperateType().equals("reqShowData")) {
                //展示数据
                String sqlResp = reqShowData(sqlReq, bodyJson);
                resp.getWriter().write(sqlResp);
                //logger.info(sqlResp);
            }
            if (sqlReq.getOperateType().equals("reqShowDataBySimple")) {
                //展示数据  显示前100行，字段注释来自于mxgc_user_column
                String sqlResp = reqShowDataBySimple(sqlReq);
                resp.getWriter().write(sqlResp);
                //logger.info(sqlResp);
            }
            if (sqlReq.getOperateType().equals("reqShowDataByLLM")) {
                //展示数据
                String sqlResp = reqShowDataByLLM(sqlReq);
                resp.getWriter().write(sqlResp);
                //logger.info(sqlResp);
            }
            if (sqlReq.getOperateType().equals("reqGetModelList")) {
                //获得模型列表 MxResponseBody
                String sqlResp = reqGetModelList(sqlReq);
                resp.getWriter().write(sqlResp);
                //logger.info(sqlResp);
            }
            if (sqlReq.getOperateType().equals("reqGetComponentList")) {
                //获得分析列表
                String sqlResp = reqGetComponentList(sqlReq);
                resp.getWriter().write(sqlResp);
                //logger.info(sqlResp);
            }
            if (sqlReq.getOperateType().equals("reqGetScreenList")) {
                //获得看板列表
                String sqlResp = reqGetScreenList(sqlReq);
                resp.getWriter().write(sqlResp);
                //logger.info(sqlResp);
            }
            if (sqlReq.getOperateType().equals("reqCopyModel")) {
                //复制模型
                String sqlResp = reqCopyModel(sqlReq);
                resp.getWriter().write(sqlResp);
                //logger.info(sqlResp);
            }
            if (sqlReq.getOperateType().equals("reqDeleteModel")) {
                //删除模型
                String sqlResp = reqDeleteModel(sqlReq);
                resp.getWriter().write(sqlResp);
                logger.info(sqlResp);
            }
            if (sqlReq.getOperateType().equals("reqDeleteComponent")) {
                //删除分析组件
                String sqlResp = reqDeleteComponent(sqlReq);
                resp.getWriter().write(sqlResp);
                logger.info(sqlResp);
            }
            if (sqlReq.getOperateType().equals("reqDeleteScreen")) {
                //删除分析看板
                String sqlResp = reqDeleteScreen(sqlReq);
                resp.getWriter().write(sqlResp);
                logger.info(sqlResp);
            }
            if (sqlReq.getOperateType().equals("reqGetDirList")) {
                //获得模型目录
                String sqlResp = getModelDir(sqlReq);
                resp.getWriter().write(sqlResp);
                logger.info(sqlResp);
            }
            if (sqlReq.getOperateType().equals("reqDeleteDir")) {
                //删除模型目录
                String sqlResp = reqDeleteDir(sqlReq);
                resp.getWriter().write(sqlResp);
                logger.info(sqlResp);
            }
            if (sqlReq.getOperateType().equals("reqCreateDir")) {
                //新增模型目录
                String sqlResp = reqCreateDir(sqlReq);
                resp.getWriter().write(sqlResp);
                logger.info(sqlResp);
            }
            if (sqlReq.getOperateType().equals("reqModifyDir")) {
                //修改模型目录
                String sqlResp = reqModifyDir(sqlReq);
                resp.getWriter().write(sqlResp);
                logger.info(sqlResp);
            }
            if (sqlReq.getOperateType().equals("reqGetUserTableLimit")) {
                //判断用户创建表的权限是否满足
                String sqlResp = reqGetUserTableLimit(sqlReq);
                resp.getWriter().write(sqlResp);
                logger.info(sqlResp);
            }
            if (sqlReq.getOperateType().equals("reqApplyShare")) {
                //申请共享模型或标签
                String sqlResp = reqApplyShare(sqlReq);
                resp.getWriter().write(sqlResp);
                logger.info(sqlResp);
            }
            if (sqlReq.getOperateType().equals("reqShareOperate")) {
                //模型共享操作
                String sqlResp = reqShareOperate(sqlReq, "1");
                resp.getWriter().write(sqlResp);
                logger.info(sqlResp);
            }
            if (sqlReq.getOperateType().equals("reqCancelShareOperate")) {
                //模型取消共享操作（模型或标签）
                String sqlResp = reqShareOperate(sqlReq, "2");
                resp.getWriter().write(sqlResp);
                logger.info(sqlResp);
            }
            if (sqlReq.getOperateType().equals("reqCreateTask")) {
                //创建任务
                String sqlResp = reqCreateTask(sqlReq);
                resp.getWriter().write(sqlResp);
                logger.info(sqlResp);
            }
            if (sqlReq.getOperateType().equals("reqTaskRun")) {
                //任务运行
                String sqlResp = reqTaskStatus(sqlReq, "run");
                resp.getWriter().write(sqlResp);
                logger.info(sqlResp);
            }
            if (sqlReq.getOperateType().equals("reqTaskStop")) {
                //任务停止
                String sqlResp = reqTaskStatus(sqlReq, "stop");
                resp.getWriter().write(sqlResp);
                logger.info(sqlResp);
            }
            if (sqlReq.getOperateType().equals("reqTaskExecute")) {
                //任务立即执行
                String sqlResp = reqTaskExecute(bodyJson);
                resp.getWriter().write(sqlResp);
                logger.info(sqlResp);
            }
            if (sqlReq.getOperateType().equals("reqGetTrainModel")) {
                //得到训练模型内容
                String sqlResp = reqGetTrainModel(bodyJson);
                resp.getWriter().write(sqlResp);
                //logger.info(sqlResp);
            }
            //从数据库中得到数据库列表
            if (sqlReq.getOperateType().equals("reqDbConfig_getDb")) {
                String sqlResp = reqDbConfig_getDb(bodyJson);
                resp.getWriter().write(sqlResp);
                logger.info(sqlResp);
            }
            //从数据库中得到模式列表
            if (sqlReq.getOperateType().equals("reqDbConfig_getSchema")) {
                String sqlResp = reqDbConfig_getSchema(bodyJson);
                resp.getWriter().write(sqlResp);
                logger.info(sqlResp);
            }
            //从数据库中得到表列表
            if (sqlReq.getOperateType().equals("reqDbConfig_getTable")) {
                String sqlResp = reqDbConfig_getTable(bodyJson);
                resp.getWriter().write(sqlResp);
                logger.info(sqlResp);
            }
            //从数据库中得到字段列表
            if (sqlReq.getOperateType().equals("reqDbConfig_getColumn")) {
                String sqlResp = reqDbConfig_getColumn(bodyJson);
                resp.getWriter().write(sqlResp);
                logger.info(sqlResp);
            }
            //根据中文字段生成英文字段
            if (sqlReq.getOperateType().equals("reqMakeCreateSql")) {
                String sqlResp = reqMakeCreateSql(bodyJson);
                resp.getWriter().write(sqlResp);
                logger.info(sqlResp);
            }
            //得到模型工厂限制配置
            if (sqlReq.getOperateType().equals("reqModelConfig_getLimit")) {
                String sqlResp = reqModelConfig_getLimit(bodyJson);
                resp.getWriter().write(sqlResp);
                logger.info(sqlResp);
            }
            //得到模型工厂模式配置
            if (sqlReq.getOperateType().equals("reqModelConfig_getSchema")) {
                String sqlResp = reqModelConfig_getSchema(bodyJson);
                resp.getWriter().write(sqlResp);
                logger.info(sqlResp);
            }
            //得到模型工厂表配置
            if (sqlReq.getOperateType().equals("reqModelConfig_getTable")) {
                String sqlResp = reqModelConfig_getTable(bodyJson);
                resp.getWriter().write(sqlResp);
                logger.info(sqlResp);
            }
            //得到模型工厂列配置
            if (sqlReq.getOperateType().equals("reqModelConfig_getColumn")) {
                String sqlResp = reqModelConfig_getColumn(bodyJson);
                resp.getWriter().write(sqlResp);
                logger.info(sqlResp);
            }
            //保存模型工厂列配置
            if (sqlReq.getOperateType().equals("reqEditColumnConfig")) {
                String sqlResp = reqEditColumnConfig(bodyJson);
                resp.getWriter().write(sqlResp);
                logger.info(sqlResp);
            }
            //保存模型工厂表配置
            if (sqlReq.getOperateType().equals("reqEditTableConfig")) {
                String sqlResp = reqEditTableConfig(bodyJson);
                resp.getWriter().write(sqlResp);
                logger.info(sqlResp);
            }
            //保存模型工厂库配置
            if (sqlReq.getOperateType().equals("reqEditDbConfig")) {
                String sqlResp = reqEditDbConfig(bodyJson);
                resp.getWriter().write(sqlResp);
                logger.info(sqlResp);
            }
            //保存模型工厂限制配置
            if (sqlReq.getOperateType().equals("reqEditLimitConfig")) {
                String sqlResp = reqEditLimitConfig(bodyJson);
                resp.getWriter().write(sqlResp);
                logger.info(sqlResp);
            }
            //根据数据库或治理结果配置模型工厂
            if (sqlReq.getOperateType().equals("reqUpdateColumnConfig")) {
                String sqlResp = reqUpdateColumnConfig(bodyJson);
                resp.getWriter().write(sqlResp);
                logger.info(sqlResp);
            }
        } catch (Exception ex) {
            ex.printStackTrace();
            logger.info(ex.getMessage());
            resp.getWriter().write(returnFail(ex.getMessage()));
        }
    }


}
